package com.fjwt.gz.service.impl;

import com.fjwt.gz.core.exception.BizException;
import com.fjwt.gz.db.entity.ActivityMchTimesEntity;
import com.fjwt.gz.service.mapper.ActivityMchTimesMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 商户参与活动抽奖次数表 (商户作为C端消费者身份参与活动) 服务实现类
 * </p>
 *
 * @author shiyonghao
 * @since 2025-04-09
 */
@Slf4j
@Service
public class ActivityMchTimesService extends ServiceImpl<ActivityMchTimesMapper, ActivityMchTimesEntity> {

    /**
     * 减少库存
     */
    public void reduceNum(ActivityMchTimesEntity activityMchTimesEntity) {
        if (activityMchTimesEntity.getTimesConsume() < activityMchTimesEntity.getTimesNum()) {
            activityMchTimesEntity.setTimesConsume(activityMchTimesEntity.getTimesConsume() + 1);
            updateById(activityMchTimesEntity);
        } else {
            throw new BizException("商户参与活动次数超发");
        }
    }
}
